import { createRouter, createWebHistory } from 'vue-router';
import HomeView from '../views/HomeView.vue';

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/',
            name: 'about',
            // route level code-splitting
            // this generates a separate chunk (About.[hash].js) for this route
            // which is lazy-loaded when the route is visited.
            component: () => import('../views/AboutView.vue'),
        },
        {
            path: '/home',
            name: 'home',
            // route level code-splitting
            // this generates a separate chunk (About.[hash].js) for this route
            // which is lazy-loaded when the route is visited.
            component: () => import('../views/HomeView.vue'),
            // keep-alive是实现
            meta: {
                keepAlive: true,
                type: 4,
                scrollTop: 0,
            },

            // 第二种方法，给路由自己添加守卫
        },
    ],
    // // 第三种方法
    // scrollBehavior(to, from, savedPosition) {
    //     console.log(to, from);
    //     console.log(savedPosition);
    //     // 也可以设置指定的路由
    //     // return 期望滚动到哪个的位置
    //     if (savedPosition) {
    //         console.log('111');
    //         return savedPosition;
    //     } else {
    //         return { x: 0, y: 0 };
    //     }
    // },
});

export default router;
